<template>
  <div>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <van-cell v-for="item in relults" 
      :key="item.id" 
        :title="item.remark"
        center
      >
      <template #label>
          <div>交易金额{{item.amount}}</div>
          <div>余额{{item.balance}}</div>
      </template>

      <template #extra>
          <div>{{formatTime(item.createTime)}}</div>
      </template>
      </van-cell>
    </van-list>
  </div>
</template>
<script>
import { formatDate } from "@/utils/date";
import { finUserLine } from "@/api/blance";
export default {

  data() {
    return {
      active: "0",
      relults: [],
      loading: false,
      finished: false,
      refreshing: false,

      param: {
        status: "1",
        pageSize: 10,
        pageNum: 1
      }
    };
  },
  methods:{
   formatTime(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      let date = new Date(
        time
          .substr(0, 19)
          .replace(/-/g, "/")
          .replace("T", " ")
      );
      return formatDate(date, "yyyy-MM-dd hh:mm:ss");
    },
  onLoad() {
    if (this.refreshing) {
      this.relults = [];
      this.param.pageNum = 1;
      this.refreshing = false;
    }

    finUserLine(this.param).then(response => {
      this.relults = this.relults.concat(response.data);
      if (response.data.length == 0) {
        this.finished = true;
      }
      this.param.pageNum = this.param.pageNum + 1;
      this.loading = false;
    });
  },

  onRefresh() {
    // 清空列表数据
    this.finished = false;

    // 重新加载数据
    // 将 loading 设置为 true，表示处于加载状态
    this.loading = true;
    this.onLoad();
  }
        
  }
};
</script>